<template>
  <div @click="handle">
    <!-- 无图片文章模板 -->
    <div  class="content-text" v-if="postData.type ===1 && (postData.cover.length < 3 && postData.cover.length >0)">
      <div class="center">
        <p class="title">{{postData.title}}</p>
        <div class="comment">
          <span>{{postData.user.nickname}}</span>
          <span>{{postData.comment_length}}评论</span>
        </div>
      </div>
      <div class="img">
        <img  :src="postData.cover[0].url | fixUrl" alt />
      </div>
    </div>
    <!-- 三张图片的文章模板 -->
    <div class="content-text" v-if="postData.type ===1 && postData.cover.length >=3">
      <div class="center">
        <p class="title-img">{{postData.title}}</p>
        <div class="img moreimg">
          <img :src="postData.cover[0].url |fixUrl" alt />
          <img :src="postData.cover[1].url |fixUrl" alt />
          <img :src="postData.cover[2].url |fixUrl" alt />
        </div>
        <div class="comment">
          <span>{{postData.user.nickname}}</span>
          <span>{{postData.comment_length}}评论</span>
        </div>
      </div>
    </div>
    <!-- 视频的文章模板 -->
    <div class="content-text" v-if="postData.type===2">
      <div class="iconfont iconshipin myvideo"></div>
      <div class="center">
        <p class="title-img">{{postData.title}}</p>
        <div class="video">
          <img :src="postData.cover[0].url | fixUrl" alt />
        </div>
        <div class="comment">
          <span>{{postData.user.nickname}}</span>
          <span>{{postData.comment_length}}评论</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: ['postData'],
  methods: {
    handle() {
      this.$router.push('/news/' + this.postData.id)
    }
  },
  filters: {
    fixUrl(url) {
      const reg = /^http/
      if (!reg.test(url)) {
        return 'http://127.0.0.1:3000' + url
      } else {
        return url
      }
    }
  }
}
</script>
<style lang="less" scoped>
// <!-- 无图片文章模板 -->
.content-text {
  padding: 2.778vw 2.778vw;
  display: flex;
  align-items: center;
  border-bottom: 0.278vw solid #eee;
  margin-top: 4.167vw;

  position: relative;
  .title {
    width: 61.111vw;
    line-height: 5.556vw;
  }
  .comment {
    height: 9.722vw;
    span {
      font-size: 3.333vw;
      margin-right: 5.556vw;
      color: #999;
    }
  }
}
// 三张图片的文章模板
.title-img {
  line-height: 5.556vw;
  padding: 0 2.778vw;
}
.moreimg {
  img {
    width: 33% !important;
  }
}
.img {
  height: 20.556vw;
  display: flex;
  justify-content: space-between;
  img {
    height: 100%;
    width: 31.111vw;
    object-fit: cover;
  }
}
// 视频的文章模板
.video {
  width: 100%;
  height: 47.222vw;
  img {
    width: 100%;
    height: 47.222vw;
    object-fit: cover;
  }
}
.myvideo {
  background: rgba(255, 255, 255, 0.3);
  position: absolute;
  left: 50%;
  transform: translate(-50%);
  width: 16.667vw;
  height: 16.667vw;
  text-align: center;
  line-height: 16.667vw;
  font-size: 13.889vw;
  border-radius: 50%;
  color: #888;
}
</style>